<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\Translation\Formatter\IntlFormatter;

/**
 * App\CustomerClue
 *
 * @property int $id
 * @property string $customer_name 客户名称
 * @property string $contact 联系方式
 * @property string $province 省
 * @property string $city 市
 * @property string $area 区
 * @property string $address 地址
 * @property int $creator_id 创建者
 * @property int $is_invalid 是否无效
 * @property string $remark 备注
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\CustomerClue onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereArea($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereContact($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereCreatorId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereCustomerName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereIsInvalid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereProvince($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\CustomerClue withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\CustomerClue withoutTrashed()
 * @mixin \Eloquent
 * @property int $is_select 是否已被业务员选择
 * @property string $wechat 微信
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereIsSelect($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereWechat($value)
 * @property int $user_id 用户id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\CustomerClue whereUserId($value)
 */
class CustomerClue extends Model
{
    use SoftDeletes;

    public static function getCustomerInfo($customer_clues_id){
        return self::whereId($customer_clues_id)->first() ?? [];
    }

    public static function getCustomerStaffName($userId = ''){
        $data = [
            'id' => '',
            'realname' => ''
        ];

        if(empty($userId))
            return $data;

        $customerClue = self::whereUserId($userId)->first();
        if(!$customerClue)
            return $data;

        $staffId = CustomerXStaff::whereCustomerCluesId($customerClue->id)->first();
        if(!$staffId)
            return $data;

        $staff = Staff::whereId($staffId->staff_id)->first();
        if($staff){
            $data['id'] = $staff->id;
            $data['realname'] = $staff->realname;
        }

        return $data;
    }
}
